<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/22
 * Time: 1:38
 */

namespace app\common\model;


use think\Model;

class Brand extends Model
{
    //连接数据库
    protected $table= 'shop_Brand';
    protected $pk= 'bid';
    //品牌添加何编辑
    public function add($data){
        $bid=input('param.bid');
        if($bid !==null){
            //编辑
            $res = $this->validate(true)->save($data,['bid' => $bid]);
            if(false === $res){
                // 验证失败 输出错误信息
                return ['valid'=>0,'msg'=>'修改失败'];
            }else{

                return ['valid'=>1,'msg'=>'修改成功'];
            }
        }else {
            //添加
            $result = $this->validate(true)->save($data);
            if (false == $result) {
                return ['valid' => 0, 'msg' => $this->getError()];
            } else {
                return ['valid' => 1, 'msg' => '添加成功！'];
            }
        }

    }
    //删除
    public function del($bid){
        $res =db('Brand')->delete($bid);
        if ($res){
            return ['valid'=>1,'msg'=>'删除成功'];
        }else{
            return ['valid'=>0,'msg'=>'删除失败'];
        }
    }
}